const { DataTypes } = require('sequelize')
const seq = require('../utils/seq')
const moment = require('moment')

/**
 *菜单id：uuid
  菜单名称：name  string
  菜单url：url   string
  上级菜单id：pid  uuid
  菜单icon：icon   string
  组件路径：component  string
  排序：order 用于菜单排序，谁前谁后显示：int
  类别：type 目录/菜单：string
  备注信息：remark string
  创建时间：ctime string
  更改时间：mtime string
  是否外链：is_frame boolean
  是否启用：status   boolean 1:true 0:false
  是否在菜单上显示(为了解决/edit等)：visible   boolean 1:true 0:false
 */
module.exports = seq.define('menu', {
  id: {
    type: DataTypes.UUID,
    primaryKey: true,
    allowNull: false,
    defaultValue: DataTypes.UUIDV4,
    comment: 'uuid'
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '菜单名称'
  },
  path: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '菜单path'
  },
  pid: {
    type: DataTypes.UUID,
    allowNull: true,
    comment: '上级菜单id'
  },
  icon: {
    type: DataTypes.STRING,
    comment: '菜单icon'
  },
  component: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '组件路径'
  },
  order: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '菜单排序'
  },
  type: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '类别'
  },
  remark: {
    type: DataTypes.STRING,
    comment: '备注信息'
  },
  ctime: {
    type: DataTypes.STRING,
    defaultValue: moment().format('YYYY-MM-DD HH:mm:ss'),
    comment: '创建时间'
  },
  mtime: {
    type: DataTypes.STRING,
    defaultValue: moment().format('YYYY-MM-DD HH:mm:ss'),
    comment: '更改时间'
  },
  status: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    comment: '状态（是否启用）'
  },
  visible: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    comment: '是否在菜单上显示'
  },
  is_frame: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    comment: '是否外链',
  }
})